#!/bin/bash
#========================================================================
# Author: YSLin
# Email: 
# File Name: ifcase.sh
# Description: 
#   
#Two powerful flow control mechanics are available in the shell:
#	-The if statement
# Edit History: 
#   2010-12-17    File created.
#========================================================================

read -p "Please input (Y/N): " yn
#|| : OR, && : AND
if [ "$yn" == "Y" ] || [ "$yn" == "y" ]; then
	echo "OK, continue"
	exit 0
fi
#-o : OR, -a : AND
if [ "$yn" == "N" -o "$yn" == "n" ]; then
	echo "Oh, interrupt!"
	exit 0
fi
echo "I don't know what your choice is" && exit 0

# ! : NOT
# true指令會永遠傳回值(終止碼=0)
if ! true; then
    echo true
else
    echo false
fi


#pipe |, not or || 
if id | grep yslinff  
then
	echo "1"
elif id | grep root
then
	echo "2"
else
	echo "3"
fi

#if list1 ; then 
#	list2  
#elif list3 ; then 
#	list4  
#else 
#	list5 
#fi 

if [ $? -eq 0 ] ; then
	echo "Command was successful." ;
elif id;then
	echo "";
else
	echo "";
fi

# 「tty -s」在標準輸入為終端的時候，傳回終止碼0。若不是終端的話，則傳回非0值
# 
if tty -s; then
    # 在終端中執行
    echo "I'm running on a terminal."
else
    # 標準輸入被重新導向，或有使用pipe
    echo "Hmm, standard input is piped or redirected."
fi

# 取得現在時間的「時」的部分
hour=`date +%H`

# 若是4點到12點則顯示「Good morning!」
# 若是12點到17點則顯示「Good afternoon!」
# 若是17點到21點則顯示「Good evening!」
# 若是21點到隔天2點則顯示「Good night...」
# 其它時間則顯示「Don't you have to go to bed?」

if [ $hour -ge 5 -a $hour -lt 12 ]; then
    echo "Good morning!"
elif [ $hour -ge 12 -a $hour -lt 17 ]; then
    echo "Good afternoon!"
elif [ $hour -ge 17 -a $hour -lt 21 ]; then
    echo "Good evening!"
elif [ $hour -lt 2 -o $Hour -ge 21 ]; then
    echo "Good night..."
else
    echo "Hmm, it seems to be midnight. Don't you have to go to bed?"
fi
